# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:chrome_version_powershell1_0.py
@Time:2024/10/30 9:00

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

import re
import subprocess

def get_chrome_version():
    try:
        # 使用命令行工具获取Chrome的安装路径
        command = "reg query \"HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon\" /v \"version\""
        result = subprocess.run(command, capture_output=True, text=True, shell=True)
        if result.returncode == 0:
            # 使用正则表达式从输出中提取版本号
            version_match = re.search(r'version\s+REG_SZ\s+(\d+\.\d+\.\d+\.\d+)', result.stdout)
            if version_match:
                return version_match.group(1)
        else:
            print("Error querying Chrome version:", result.stderr)
    except Exception as e:
        print("An error occurred:", e)

    return None

chrome_version = get_chrome_version()
if chrome_version:
    print("Chrome version:", chrome_version)
else:
    print("Chrome is not installed or version could not be determined.")